<?php
use yii\helpers\Html;
use yii\helpers\Url;
use app\lib\WeixinUtils;

/* @var $this yii\web\View */
/* @var $content string 字符串 */


$web = Url::to("@web");

?>

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <title>朵拉盒子</title>
    <link rel="stylesheet" href="<?=$web?>/css/bag/shopping_cart.css" />
    <link type="text/css" href="<?=$web?>/css/bag/global.css" rel="stylesheet"/>
    <script type="text/javascript" src="<?=$web?>/js/jquery.js"></script>
    <script type="text/javascript" src="<?=$web?>/js/tools.js"></script>
    <script type="text/javascript">

        $(function() {
            // 任何需要执行的js特效
            var w = $(document).width();
            if(w == 375){
                $(".commodity_to_left").css({"width":"34%"});
                $(".commodity_to_right").css({"width":"63%"});
                $(".im1").css({"width":"37%"});
                $(".im2").css({"width":"6%"});
                $(".im1").css({"margin-left":"30%"});
                $(".down_right").css({"width":"28.2%"});
            }else if(w == 414){
                $(".commodity_to_left").css({"width":"31%"});
                $(".commodity_to_right").css({"width":"66%"});
                $(".im1").css({"width":"37.5%"});
                $(".im2").css({"width":"6.5%"});
                $(".im1").css({"margin-left":"30%"});
                $(".down_right").css({"width":"28.5%"});
            }else if(w > 414){
                $(".main").css({"width":"414px","height":"auto","margin-left":"auto","margin-right":"auto"});
                $(".commodity_to_left").css({"width":"31%"});
                $(".commodity_to_right").css({"width":"66%"});
                $(".im1").css({"width":"37.5%"});
                $(".im2").css({"width":"6.5%"});
                $(".im1").css({"margin-left":"30%"});
                $(".down_right").css({"width":"28.5%"});
                $(".down1").css({"width":"414px","height":"auto","margin-left":(w-414)/2});
            }
        });

        $(document).ready(function(){

            $(".RadioClass").change(function(){
                if($(this).is(":checked")){
                    //$(".RadioSelected:not(:checked)").removeClass("RadioSelected");
                    $(this).next("label").addClass("RadioSelected");
                }else{
                    $(this).next("label").removeClass("RadioSelected");
                }
            });
        });

        $(document).ready(function(){

            $(".RadioClass1").change(function(){
                if($(this).is(":checked")){
                    //$(".RadioSelected:not(:checked)").removeClass("RadioSelected");
                    $(this).next("label").addClass("RadioSelected1");
                }else{
                    $(this).next("label").removeClass("RadioSelected1");
                }
            });
        });
        function addnum(me){
            var t=$(me).parent().find('input[class*=text_box]');
            var v=parseInt(t.val());
            if(v>99){
                alert("买的太多了");
                return;
            }

//            t.val(v+1);
            var code=$(me).parent().find('.hidden_GOODS_CODE').val();
            incNum(code,1,t);
        }

       function decnum(me){
           var t=$(me).parent().find('input[class*=text_box]');
           var v=parseInt(t.val());
           if(v<=1){
               //alert("买的太多了");
               return;
           }

//           t.val(v-1);

           var code=$(me).parent().find('.hidden_GOODS_CODE').val();
           incNum(code,-1,t);
        }
        var good_tpl="";
        $(function ($) {
            good_tpl = returnstring("<?=$web?>/js/bag/cart_good.tpl");
            loadCartList();
        });
        function loadCartList() {
            var data = {};
            var re = returnjson("<?=Url::to(['wx-bag/get-goods-cart-handle'])?>", data);
            if (re.flag == 0) {
                alert(re.msg);
                return;
            } else {
                var target = $("#v_cart");
                target.empty();
                $('#v_count').html("("+re.TOTALNUM+")");
                $('#v_totalprice').html(re.TOTALPRICE);
                $.each(re.cartList, function (i, item) {
                    var dom = document.createElement("DIV");
                    dom.innerHTML = good_tpl._format({
                        web:'<?=$web?>',
                        GOODS_IMG_URL: item.GOODS_IMG_URL || '<?=$web?>/logo.jpg',
                        NUM: item.NUM,
                        GOODS_NAME: item.GOODS_NAME,
                        GOODS_CODE: item.GOODS_CODE,
                        PRICE:item.PRICE
                    });
                    target.get(0).appendChild(dom);
                });

            }

        }
        function  incNum(goods_code,addnum,t){
            var data = {};
            data.goods_code=goods_code;
            data.addnum=addnum;
            var re = returnjson("<?=Url::to(['wx-bag/inc-goods-to-cart-handle'])?>", data);
            if (re.flag == 0) {
                alert(re.msg);
                return;
            } else {
                var v=parseInt(t.val());
                t.val(v+addnum);
                $('#v_count').html("("+re.TOTALNUM+")");
                $('#v_totalprice').html(re.TOTALPRICE);
                //loadCartList();
            }
        }
        function del_goods(me){
            var code=$(me).parent().find('.hidden_GOODS_CODE').val();
//            alert(code);
            var data = {};
            data.goods_code=code;
            var re = returnjson("<?=Url::to(['wx-bag/del-goods-to-cart-handle'])?>", data);
            if (re.flag == 0) {
                alert(re.msg);
                return;
            } else {
//                $(me).parent().remove();
                loadCartList();
            }

        }

        function  create_order(){

            var data = {};
            var re = returnjson("<?=Url::to(['wx-bag/create-cart-to-order-handle'])?>", data);
            if (re.flag == 0) {
                alert(re.msg);
                return;
            } else {
                //
                window.location.href = "<?=Url::to(["wx-bag/view-order-nav"]);?>?code="+re.order_id;


            }
        }

        function href_home(){
            window.location.href = "<?=Url::to(["wx-home/home"]);?>";
        }
    </script>
</head>

<body>


<div class="main">
    <div id="v_cart">
    <!--<div class="cart">
        <div class="cart_bg">
            <div class="cart_left">
                <input id="Radio1" type="radio" class="RadioClass" name="group1">
                <label id="Label1" for="Radio1" class="RadioLabelClass"></label>
            </div>
            <div class="cart_center">
                <img class="im1" src="<?/*=$web*/?>/img/bag/shopping_cart_image/cart.png" width="100%" height="100%"/>
            </div>
            <div class="cart_right">
                <div class="cart_right_number">
                    <table class="cart_right_number_table" cellpadding="0" cellspacing="0" border="0">
                        <tr>
                            <td id="re" align="center" width="42">
                                <img src="<?/*=$web*/?>/img/bag/shopping_cart_image/cart_re.png" width="24%" style="display:block;"/>
                            </td>
                            <td align="center" width="40"><input id="number" type="text" style="width:40px; text-align:center; color:rgb(113,201,145); border:none;" value="1"/></td>
                            <td id="add" align="center" width="42">
                                <img src="<?/*=$web*/?>/img/bag/shopping_cart_image/cart_add.png" width="24%" style="display:block;"/>
                            </td>
                        </tr>
                    </table>
                </div>
                <div class="cart_right_title">
                    <div class="cart_right_title_text">MicroMax LED Pocket 100X 显微镜</div>
                </div>
                <div class="cart_right_price">
                    <div class="cart_right_price_text">¥199</div>
                </div>
            </div>
        </div>
    </div>-->
    </div>
    <div class="down1">
        <div class="down_left">
            <div class="down_left_text">
                <label class="down_text" style="font-size: 0.9em;">合计：<label style="font-size: 0.6em;">¥</label>
                    <label style="font-size: 1.4em;" id="v_totalprice">***</label></div>
        </div>
        <div class="down_center" onclick="href_home()">
            还想再选选
        </div>
        <div class="down_right">
            <div class="down_right_text" onclick="create_order();">去结算<label style="font-size: 0.75em;" id="v_count">（*）</label
            </div>
        </div>
    </div>
</div>

</body>
</html>

